package com.hl.wechat.demo.controller;

import com.hl.wechat.demo.entity.ApiResult;
import com.hl.wechat.demo.entity.User;
import com.hl.wechat.demo.entity.WxLogin;
import com.hl.wechat.demo.service.impl.UserServiceImpl;
import com.hl.wechat.demo.utils.ApiResultUtils;
import com.hl.wechat.demo.websocket.WebSocketListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    UserServiceImpl userService;

    @Autowired
    WebSocketListener webSocketListener;

    @PostMapping("addUser")
    public ApiResult addUser(
            @RequestParam("id")String id,
            @RequestParam("nickName")String name,@RequestParam("profileUrl")String url){
        userService.addUser(new User(name,url,id));
        return ApiResultUtils.success("OK");
    }

    @GetMapping("listUser")
    public ApiResult listUser(){
        return ApiResultUtils.success(userService.listUser());
    }

    @PostMapping("wxLogin")
    public ApiResult wxLogin(@RequestParam("code")String code){
        WxLogin wxLogin = userService.wxLogin(code);
        return ApiResultUtils.success(wxLogin);
    }
}
